/*

    private int resx, resy; // viewport resolution
    private float h, w, aspect; // window height, width and aspect ratio

    Vector<RT_Object> objects;

    private Raytracer03_TriangleSnippet() {
	try {
	    
	    gui.addObject(RTFileReader.read(T_Mesh.class, new File("data/dreieck1.dat")));
	    
	    objects = gui.getObjects();

	} catch (IOException e) {
	    e.printStackTrace();
	}
    }
    
    
    



    private Color traceRayAndGetColor(float rayEx, float rayEy, float rayEz, float rayVx, float rayVy, float rayVz) {
	// RTFile scene = gui.getFile();

	double minT = Float.MAX_VALUE;
	int minObjectsIndex = -1;
	int minIndex = -1;
	float[] minIP = new float[3];
	float[] minN = new float[3];
	float[] minMaterial = new float[3];
	float minMaterialN = 1;
	float bu = 0, bv = 0, bw = 1;

	float[] v = new float[3];
	float[] l = new float[3];

	// viewing vector at intersection point
	v[0] = -rayVx;
	v[1] = -rayVy;
	v[2] = -rayVz;
	normalize(v);

	RTFile scene;
	I_Sphere sphere;
	T_Mesh mesh;

	// loop over all scene objects to find the nearest intersection, that
	// is:
	// object with number minObjectIndex, if it is a mesh the corresponding
	// face has the index minIndex
	// minT is the minimal factor t of the ray equation s(t)=rayE+t*rayV
	// where the nearest intersection takes place
	// minMaterial and minMaterialN is the material to use at the nearest
	// intersection point
	for (int objectsNumber = 0; objectsNumber < objects.size(); objectsNumber++) {
	    scene = objects.get(objectsNumber);

	    // object is an implicit sphere?
	    if (scene.getHeader() == "IMPLICIT_SPHERE") {
		sphere = (I_Sphere) scene;


	    }

	    // object is a triangle mesh?
	    else if (scene.getHeader() == "TRIANGLE_MESH") 
	    {
			mesh = (T_Mesh) scene;
	
			float t;
			float[] n;
			float[] ip = new float[3];
	
			float a, rayVn, pen;
			float[] p1, p2, p3;
			float[] ai = new float[3];
	
			// loop over all triangles
			for (int i = 0; i < mesh.triangles.length; i++) {
			    // get the three vertices
			    p1 = 
			    p2 = 
			    p3 = 
	
			    // intermediate version
			    // calculate normal n and triangle area a
			     n = new float[3];
			     a = 
	
	
			    rayVn = 
	
			    // backface? => next triangle
			    if (rayVn >= 0)
				continue;
	
			    pen = 
	
			    // no intersection point? => next triangle
			    if (Math.abs(rayVn) < 1E-7)
				continue;
	
			    // calculate intersection point with plane along the ray
			    t = 
	
			    // already a closer intersection point? => next triangle
			    if (t >= minT)
				continue;
	
			    // the intersection point with the plane
			    ip[0] = 
			    ip[1] = 
			    ip[2] = 
	
			    // no intersection point with the triangle? => next
			    // triangle
			    if (!triangleTest(ip, p1, p2, p3, a, ai))
				continue;
	
			    // from here: t < minT and triangle intersection
			    // I'm the winner until now!
	
			    minT = t;
			    minObjectsIndex = objectsNumber;
			    minIndex = i;
	
			    // prepare everything for shading alternatives
	
			    // the intersection point
			    minIP[0] = ip[0];
			    minIP[1] = ip[1];
			    minIP[2] = ip[2];
	
			    switch (mesh.fgp) {
			    case 'f':
			    case 'F':
				
				 // the normal is the surface normal 
				 minN[0] = n[0];
				 minN[1] = n[1]; 
				 minN[2] = n[2];
				  
				 // the material is the material of the first triangle point 
				 int matIndex = mesh.verticesMat[mesh.triangles[minIndex][0]];
				 minMaterial = mesh.materials[matIndex]; 
				 minMaterialN= mesh.materialsN[matIndex];
				
				break;
			    
			    }
			}
	    } else
		continue; // return null;
	}

	// no intersection point found => return with no result
	if (minObjectsIndex == -1)
	    return null;

	// light vector at the intersection point
	l[0] = ICenter[0] - minIP[0];
	l[1] = ICenter[1] - minIP[1];
	l[2] = ICenter[2] - minIP[2];
	normalize(l);

	// decide which shading model will be applied

	// implicit: only phong shading available => shade=illuminate
	if (objects.get(minObjectsIndex).getHeader() == "IMPLICIT_SPHERE")
	    return phongIlluminate(minMaterial, minMaterialN, l, minN, v, Ia, Ids);

	// triangle mesh: flat, gouraud or phong shading according to file data
	else if (objects.get(minObjectsIndex).getHeader() == "TRIANGLE_MESH") {
	    mesh = ((T_Mesh) objects.get(minObjectsIndex));
	    switch (mesh.fgp) {
	    case 'f':
	    case 'F':
		// illumination can be calculated here
		// this is a variant between flat und phong shading
		return phongIlluminate(minMaterial, minMaterialN, l, minN, v, Ia, Ids);


	    }

	}
	return null;

	// intermediate version
	// Random rd = new Random();
	// return new Color(rd.nextFloat(), rd.nextFloat(), rd.nextFloat());
    }



    // calculate normalized face normal fn of the triangle p1, p2 and p3
    // the return value is the area of triangle
    // CAUTION: fn is an output parameter; the referenced object will be
    // altered!
    private float calculateN(float[] fn, float[] p1, float[] p2, float[] p3) {
	float ax, ay, az, bx, by, bz;

	// a = Vi2-Vi1, b = Vi3-Vi1



	

	// n =a x b

	
	

	// normalize n, calculate and return area of triangle
	return normalize(fn) / 2;
    }

    // calculate triangle test
    // is p (the intersection point with the plane through p1, p2 and p3) inside
    // the triangle p1, p2 and p3?
    // the return value answers this question
    // a is an input parameter - the given area of the triangle p1, p2 and p3
    // ai will be computed to be the areas of the sub-triangles to allow to
    // compute barycentric coordinates of the intersection point p
    // ai[0] is associated with bu (p1p2p) across from p3
    // ai[1] is associated with bv (pp2p3) across from p1
    // ai[2] is associated with bw (p1pp3) across form p2
    // CAUTION: ai is an output parameter; the referenced object will be
    // altered!
    private boolean triangleTest(float[] p, float[] p1, float[] p2, float[] p3, float a, float ai[]) {
	float tmp[] = new float[3];

	ai[0] = 
	ai[1] = 
	ai[2] = 

	if 
	    return true;

	return false;
    }



    public static void main(String[] args) {
	Raytracer03_TriangleSnippet rt = new Raytracer03_TriangleSnippet();

	// rt.doRayTrace();
    }
}
*/
